<template>
    <el-dialog title="新增学科" :visible.sync="dialogFormVisible">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="学科名称" prop="subjectName">
                <el-input v-model="ruleForm.subjectName"></el-input>
            </el-form-item>
            <el-form-item label="是否显示" prop="isFrontDisplay">
                <el-switch v-model="ruleForm.isFrontDisplay" :active-value="1" :inactive-value="0"></el-switch>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm">确认</el-button>
                <el-button @click="resetForm">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>
<script>
import { add } from '@/api/hmmm/subjects.js'
export default {
  data () {
    return {
      dialogFormVisible: false,
      ruleForm: {
        subjectName: '',
        isFrontDisplay: 1
      },
      rules: {
        subjectName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    openDialog () {
      this.dialogFormVisible = true
    },
    submitForm () {
      this.$refs.ruleForm.validate(async (value) => {
        if (value) {
          await add(this.ruleForm)
          this.$emit('ADD_ROLE_SUCCESS')
          this.resetForm()
        }
      })
    },
    resetForm () {
      this.$refs.ruleForm.resetFields()
      this.dialogFormVisible = false
    }

  }
}
</script>
